package cn.gson.springboot.controllers;

import java.util.HashMap;  
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.springboot.model.pojos.FactoryYk;
import cn.gson.springboot.model.service.FactoryYkService;

@Controller
public class FactoryYkController {
	@Autowired
	private FactoryYkService fs;
	
	//药库供应商
	@RequestMapping("yaoku-gongyingshang")
	public void yaokuGongyingshang(Model model) {
	} 
	//查询所有
	@RequestMapping("gysbiaoge")
	@ResponseBody
	public Map<String,Object> hosLikeTableSmt(
			@RequestParam("page")int page,
			@RequestParam("rows")int rows){
		//进行分页
		Page<Object> pg = PageHelper.startPage(page, rows);
		List<FactoryYk> findall=fs.findAll();
		
		//进行数据格式转换和封装
		Map<String,Object> map = new HashMap<>();
		map.put("total", pg.getTotal());//封装总记录数
		map.put("rows", findall);//封装当前页的内容
		
		return map; 
	}
	//药品界面的新增供应商下拉列表
	@RequestMapping("aaaa")
	@ResponseBody
	public List<FactoryYk> gysaa() {
		List<FactoryYk> list = fs.findAll();
		System.out.println(list.size()+"----");
		return fs.findAll();
	}
	
	//供应商新增
		@RequestMapping("gysxz")
		@ResponseBody
		public void gongyingshangxzeng(@RequestParam("factoryName")String factoryName,
				@RequestParam("factoryPeople")String factoryPeople,
				@RequestParam("factoryPhone")String factoryPhone) {
			FactoryYk ss=new FactoryYk();				
			ss.setFactoryName(factoryName);//供应商名称
			ss.setFactoryPeople(factoryPeople);//联系人
			ss.setFactoryPhone(factoryPhone);//电话
				
			fs.xinzeng(ss);
		}
	
	//修改
	@RequestMapping("xiugai")
	@ResponseBody
	public void xiugai(Integer idd,String fname,String rname,String dianhua) {
		fs.update(idd, fname, rname, dianhua);
	}
	
	//根据供应商编号查询药品
	@RequestMapping("gysid")
	@ResponseBody
	public JSONArray findgysyp(String factory_name) {
		JSONArray findgysyp = fs.findgysyp(factory_name);
		System.out.println(findgysyp.toString());
		return findgysyp;
	}
}
